<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <% String contextPath = request.getContextPath(); 
    request.setAttribute("contextPath", contextPath);%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">


<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>新增公告</title>

    <!-- Bootstrap Core CSS -->
    <link href="${contextPath}/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="${contextPath}/css/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="${contextPath}/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="${contextPath}/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!--common Css-->
    <link href="${contextPath}/css/common.css" rel="stylesheet">
    
    <link href="${contextPath}/iconfont/iconfont.css" rel="stylesheet">

</head>

<body>

<div id="wrapper">

    <!-- Navigation -->
    <%@include file="nav.jsp"%>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">新增公告</h3>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-6">
                                <form role="form" class="form-horizontal" method="post" enctype="multipart/form-data" action="">
                                    
                                    <div class="form-group">
                                        <label for="name" class="col-sm-2 control-label">公告主题</label>
                                        <div class="col-lg-10">
                                            <input type="name" class="form-control" id="noticeTheme" name="noticeTheme" placeholder='公告主题不能超过50个字符'>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="nickname" class="col-sm-2 control-label">公告标题</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="noticeTitle" name="noticeTitle" placeholder='公告标题不能超过50个字符'>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="phone" class="col-sm-2 control-label">欢迎语</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="welcome" name="welcome" placeholder='欢迎语不能超过20个字符'>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="password" class="col-sm-2 control-label">公告详情</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="noticeInfo" name="noticeInfo" placeholder='公告详情不能超过500个字符'>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="password" class="col-sm-2 control-label">备注</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="remark" name="remark" placeholder='备注不能超过150个字符'>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="rePassword" class="col-sm-2 control-label">结束语</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="finish" name="finish" placeholder='结束语不能超过20个字符'>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="rePassword" class="col-sm-2 control-label">署名</label>
                                        <div class="col-lg-10">
                                            <input type="text" class="form-control" id="signature" name="signature" placeholder='署名不能超过20个字符'>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-3">
                                            <button type="button" class="btn btn-default" id="sub" >提交</button>
                                            <button type="reset" class="btn btn-default">取消</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <!-- /.row (nested) -->
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
    </div>
    <!-- /#page-wrapper -->

</div>




<!-- /#wrapper -->

<!-- jQuery -->
<script src="${contextPath}/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="${contextPath}/js/bootstrap.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="${contextPath}/js/metisMenu.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="${contextPath}/js/sb-admin-2.min.js"></script>

<!-- Page-Level Demo Scripts - Tables - Use for reference -->
<script>
	
    $(function () {
    	 
	$('[data-toggle="popover"]').popover();
	    	$("#sub").click(function(){
          	
            var noticeTheme = $("#noticeTheme").val();
            if(noticeTheme === ''){
            	$(".popupTip") .hide();
                return notice('公告主题不能为空');
            }else if(noticeTheme.length>50){
            	$(".popupTip") .hide();
            	return notice('公告主题已超过50个字符');
            }

            var noticeTitle = $("#noticeTitle").val();
            if(noticeTitle === ''){
            	$(".popupTip") .hide();
                return notice('公告标题不能为空');
            }else if(noticeTitle.length>50){
            	$(".popupTip") .hide();
            	return notice('公告标题已超过50个字符');
            }

            var welcome = $("#welcome").val();
            if(welcome === ''){
            	$(".popupTip") .hide();
                return notice('欢迎语不能为空');
            }else if(welcome.length>20){
            	$(".popupTip") .hide();
            	return notice('欢迎语已超过20个字符');
            }

            var noticeInfo = $("#noticeInfo").val();
            if(noticeInfo === ''){
            	$(".popupTip") .hide();
                return notice('公告详情不能为空');
            }else if(noticeInfo.length>500){
            	$(".popupTip") .hide();
            	return notice('公告详情已超过500个字符');
            }

            var remark = $("#remark").val();
            if(remark === ''){
            	$(".popupTip") .hide();
                return notice('备注不能为空');
            }else if(remark.length>150){
            	$(".popupTip") .hide();
            	return notice('备注已超过150个字符');
            }

            var finish = $("#finish").val();
            if(finish === ''){
            	$(".popupTip") .hide();
                return notice('结束语不能为空');
            }else if(finish.length>20){
            	$(".popupTip") .hide();
            	return notice('结束语已超过20个字符');
            }

           

          

        	var signature = $("#signature").val();
            if(signature === ''){
            	$(".popupTip") .hide();
                return notice('署名不能为空');
            }else if(signature.length>20){
            	$(".popupTip") .hide();
            	return notice('署名已超过20个字符');
            }
            
         

            
    	var welcome=$("#welcome").val();
    	var noticeTheme=$("#noticeTheme").val();
    	var noticeTitle=$("#noticeTitle").val();
    	var noticeInfo=$("#noticeInfo").val();
    	var remark=$("#remark").val();
    	var finish=$("#finish").val();
    	var signature=$("#signature").val();
    	
    	$.ajax({
    		url:"${contextPath}/WebManager/notice/insertWebNotice",
    		data:JSON.stringify({
    		"welcome":welcome,
    		"noticeTheme":noticeTheme,
    		"noticeTitle":noticeTitle,
    		"noticeInfo":noticeInfo,
    		"remark":remark,
    		"finish":finish,
    		"signature":signature
    		}),
    		dataType:'json',
    		contentType: "application/json;charset=utf-8",
    		type:"POST",
    		success:function(result){
    			
    			if(result.success==true){
    				//(${results.data.totalCount}%${results.data.pageSize}==0)?pageNow=${results.data.totalCount}:pageNow=${results.data.totalCount};
					window.location.href = "${contextPath}/WebManager/notice/webmsg?pageNow=1";
					
					
    				 /* if(confirm("增加成功")){
    				 
    				 	
    				 	//location.href="${contextPath}/notice/webmsg?pageNow=1";
    				 	location.href="${contextPath}/WebManager/notice/webmsg?pageNow=1"
    				 } */
    				 
    			}else{
    				 $(".popupTip") .hide();
    				 notice("增加失败");
    			}
    		}
    	
    	});
            
            
            
        });

        //提示信息封装函数
        function notice(notice) {
            var str = '';
            str += '<div class="popupTip">';
            str += notice;
            str += '<span class="glyphicon glyphicon-remove"></span>';
            str += '</div>';
            str += '</strong></div>';
            //wrapper插入str
            $("#wrapper").append(str);
        }

        //取消提示框
        $("#wrapper").on('click', '.glyphicon-remove', function(){
            $(".popupTip") .hide();
        });
        
        
        
    })
    
   
</script>

</body>

</html>
